home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11696 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  69 lines

  1. Newsgroups: comp.lang.c++
  2. Path: newsgate.melpar.esys.com!melpar!beuttel
  3. From: beuttel@pepman.mfg.melpar.esys.com (Stephen Beuttel - UC Test)
  4. Subject: OVLD >> op to input 2 doubles to obj?
  5. Sender: news@melpar.esys.com (Melpar News Administrator)
  6. Organization: E-Systems, Melpar Division
  7. Date: Fri, 15 Mar 1996 19:33:55 GMT
  8. Message-ID: <beuttel.826918435@melpar>
  9. Distribution: comp.lang.c++
  10.  
  11.  
  12. Hi,
  13.  
  14.    I'm doing an assignment for my C++ class that, in part, requires me to
  15. modify a class Complex ( as in 'complex numbers' ) to include a friend 
  16. function that overloads the stream extraction operator so that when passed
  17. a right parameter of the object( type Complex ) it will input the two
  18. float members 'real' & 'imaginary'.
  19.  
  20.    Neither my text ( _C++ How To Program_ ) or Stroustrup's book show a way
  21. to do this. Between them I see only how to overload the operator to do three
  22. things: 1) input integer members, 2) char/array members, & 3) failbits.
  23.  
  24.     Would someone in this group tell me how to do the float thing? Or where 
  25. a resource might be? Do you think I'm just going to have to create char-array 
  26. members and then do conversion?
  27. ( Seems rather lame for such a touted language ).     <8-O 
  28.  
  29.    Below's an idea of the code:
  30.  
  31. class Complex
  32. {
  33. public:
  34.    Complex(double = 0.0, double = 0.0);
  35.       :
  36.       :
  37.    friend istream &operator>>(istream &, Complex &);
  38.       :
  39. private:
  40.    double real;
  41.    double imaginary;
  42. };
  43.  
  44.    :
  45.    :
  46. istream &operator>>(istream &strm, Complex &in_obj)
  47. {
  48.       :
  49.    ??????STUFF
  50.       :
  51.    return strm;
  52. }
  53.    :
  54.    :
  55. int main( void )
  56. {
  57.    Complex a, ... ;
  58.       :
  59.       :
  60.    cin >> a;
  61.       :
  62.    return 0;
  63. }
  64.  
  65. THANKS:
  66.  
  67.    - Steve -
  68.  
  69.